package com.xw.converter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xw.dto.WxUserDTO;
import com.xw.enums.ResultEnum;
import com.xw.exception.YdException;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description:
 * @Author: y
 * @CreateDate: 9/15/21 3:38 PM
 * @Version: 1.0
 */
@Slf4j
public class WxUserJson2WxUserDTO {

    public static WxUserDTO convert(String wxUserJson) {
        Gson gson = new Gson();

        WxUserDTO wxUserDTO = new WxUserDTO();

        try {
            wxUserDTO = gson.fromJson(wxUserJson, new TypeToken<WxUserDTO>() {
            }.getType());
        } catch (Exception e) {
            log.error("[对象转换] 错误, String={}", wxUserJson);
            throw new YdException(ResultEnum.PARAM_ERROR);
        }

        return wxUserDTO;
    }
}